export class RequestFilter {
  static filterEmptyParams(obj: {}) {
    let filterObj = {};

    for (let o in obj) {
      if (obj.hasOwnProperty(o) && obj[o] !== null) {
        filterObj[o] = obj[o];
      }
    }

    return filterObj;
  }

  static filterUrlEmptyParams(urlParams: string) {
    let filterUrlParams = [];

    var params = urlParams.split('&');
    for (var i = 0; i < params.length; i++) {
      var param = params[i].split('=');
      if (param[1] && param[1] != 'undefined' && param[1] != 'null') {
        filterUrlParams.push(encodeURIComponent(param[0]) + '=' + encodeURIComponent(param[1]));
      }
    }

    return filterUrlParams.join('&');
  }
}

export default RequestFilter;
